package com.gray.quartz.core;

import org.quartz.JobDataMap;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * Created on 2019/6/24.
 *
 * @author hy
 * @since 1.0
 */
@RestController
public class CoreQuartzControllerTest {

    @Autowired
    CoreQuartz coreQuartz;

    @RequestMapping("/core")
    public void coreQuartz() throws SchedulerException {
        JobDataMap jobMap = new JobDataMap();
        jobMap.put("name", "quartz");

        Runnable runnable = () -> {
            System.out.println("定时器执行");
        };

        jobMap.put("time", 50);
        jobMap.put("runnable", runnable);

//        JobKey key1 = coreQuartz.delayTimmer(5, jobMap);
        JobKey key2 = coreQuartz.intervalTimmer(3, TimeUnit.SECONDS,GrayJob.class,jobMap);
//        JobKey key3 = coreQuartz.delayTimmer(5, jobMap);
//        JobKey key4 = coreQuartz.delayTimmer(5, jobMap);
//        JobKey key5 = coreQuartz.delayTimmer(5, jobMap);
//        JobKey key6 = coreQuartz.delayTimmer(5, jobMap);
//        JobDataMap jobMap2 = new JobDataMap();
//        jobMap2.put("name", "quartz2");
//        jobMap2.put("time", 52);
//        JobKey key7 = coreQuartz.intervalTimmer(4, jobMap2);
//        JobKey key8 = coreQuartz.cornTimmer("5/1 * * * * ? ", jobMap2);

//        coreQuartz.shutdown(key2);
//        coreQuartz.shutdown(key3);
//        coreQuartz.shutdown(key4);

    }
}
